package com.icinfo.cloud.provider.punish.common.electricsent.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.ObjectUtils;

/**
 * 描述：送达登记签收人枚举
 *
 * @author xiangyuyu
 * @date 2022/2/25 15:39
 */
@AllArgsConstructor
public enum SentRegisterReceiverTypeEnum {
    /**
     * 送达登记签收人枚举
     */
    SSDR("1", "受送达人"),
    WTDLR("2", "委托代理人"),
    DSR("3", "代收人");

    /**
     * 编码
     */
    @Getter
    private String code;
    /**
     * 描述
     */
    @Getter
    private String des;

    /**
     * 根据code获取value
     *
     * @param code 编码
     * @return 描述内容
     */
    public static String getValueByCode(String code) {
        if (ObjectUtils.isEmpty(code)) {
            return null;
        }
        for (SentRegisterReceiverTypeEnum e : SentRegisterReceiverTypeEnum.values()) {
            if (code.equals(e.getCode())) {
                return e.getDes();
            }
        }
        return code;
    }


    /**
     * 描述：根据des获取code
     *
     * @param des 描述
     * @return String code值
     * @author xiangyuyu
     * @date 2022/8/9
     * @since 1.3.2
     */
    public static String getCodeByDes(String des) {
        if (ObjectUtils.isEmpty(des)) {
            return null;
        }
        for (SentRegisterReceiverTypeEnum e : SentRegisterReceiverTypeEnum.values()) {
            if (des.equals(e.getDes())) {
                return e.getCode();
            }
        }
        return des;
    }

    /**
     * 描述：校验code是否是合法枚举
     *
     * @param code 枚举code
     * @return boolean 是否合法枚举（true-是/false-否）
     * @author XiangYuYu
     * @date 2021/09/15
     */
    public static boolean isLegalEnumCode(String code) {
        boolean flag = false;
        for (SentRegisterReceiverTypeEnum e : SentRegisterReceiverTypeEnum.values()) {
            if (e.getCode().equalsIgnoreCase(code)) {
                flag = true;
                break;
            }
        }
        return flag;
    }
}
